package mysql;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Random;

public class DijkstraTest {
	
	public static void testShortestPath(int numTests) throws SQLException{
		DB db = new DB("jdbc:mysql://localhost/mysql_db", "root", "password");
		
		ArrayList<Integer> srcNodes = db.getRandIDs(numTests);
		ArrayList<Integer> dstNodes = db.getRandIDs(numTests);
		db.close();
		Random generator = new Random();
		Dijkstra dj = new Dijkstra();
		
		
		int i = 0;
		while(i < numTests){
			
			int src = srcNodes.get(generator.nextInt( srcNodes.size()));
			int dst = dstNodes.get(generator.nextInt( srcNodes.size()));
			long start = System.nanoTime();
			dj.execute(src, dst);
			int distance = dj.getShortestDistance(dst);
			long elapsedTime = System.nanoTime() - start;
			if(distance == dj.INFINITE_DISTANCE){
				System.out.println("Nodes " + src + " and " + dst + " not connected");
			}
			else{
				System.out.println ("size " + src + "\t " + dst + "\t " + distance + " " + elapsedTime);
				i++;
			}
			
			
		}

	}
	
	
	
	public static void main(String[] args) throws SQLException {
		DijkstraTest.testShortestPath(100);

	}

}
